a=int(input())
max=0
if a<1000 or a>9999:
    print ("O")
else:
    d1=a//1000
    d2=a//100%10
    d3=a//10%10
    d4=a%10

    s=0
    for i in range(1,a//1+2):
        if a%i==0:
            s+=1
    if s==2 and a>max:
        max=a
    s=0
    for i in range(1,d1+1):
        if d1%i==0:
            s+=1
    if s==2 and d1>max:
        max=d1
    s=0
    for i in range(1,d2+1):
        if d2%i==0:
            s+=1
    if s==2 and d2>max:
        max=d2
    z=d1*10+d2
    s=0
    for i in range(1,d3+1):
        if d3%i==0:
            s+=1
    if s==2 and d3>=max:
        max=d3
    s=0
    for i in range(1,d4+1):
        if d4%i==0:
            s+=1
    if s==2 and d4>=max:
        max=d4
    s=0
    z=d1*10+d2
    for i in range(1,z+1):
        if z%i==0:
            s+=1
    if s==2 and z>=max:
        max=z
    s=0
    z=d1*100+d2*10+d3
    for i in range(1,z+1):
        if z%i==0:
            s+=1
    if s==2 and z>=max:
        max=z
    s=0
    z=d2*100+d3*10+d4
    for i in range(1, z+1):
        if z%i==0:
            s+=1
    if s==2 and z>=max:
        max=z
    s=0
    z=d3*10+d4
    for i in range(1, z+1):
        if z%i==0:
            s+=1
    if s==2 and z>=max:
        max=z
    print(max)



